home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_055 / vsprites / vsprite.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  213 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  *                      V S P R I T E   E X A M P L E                       *
  4.  * by Eric Cotton                                       *
  5.  *      (c) 1986 Commodore-Amiga, Inc.                                      *
  6.  * Posted to Bix by Andy Finkel
  7.  ****************************************************************************/
  8.  
  9. #include "vsprite.h"            /* standard includes & definitions */
  10.  
  11. #define WIDTH 320
  12. #define HEIGHT 200
  13. #define DEPTH 2
  14.  
  15. extern struct Custom custom;
  16. extern struct Window *OpenWindow(); /* function to open a window */
  17. extern struct ViewPort *ViewPortAddress(); /* function to get ViewPort add. */
  18. extern struct IntuiMessage *GetMsg(); /* function to retrieve IntuiMessage */
  19.  
  20. extern struct VSprite *MakeVSprite();
  21. extern struct VSprite *MakeBob();
  22.  
  23. struct GfxBase *GfxBase;        /* pointer to Graphics library */
  24. struct IntuitionBase *IntuitionBase; /* pointer to Intuition library */
  25.  
  26. struct Window *window;          /* pointer to window */
  27. struct RastPort *rport;         /* pointer to window's RastPort */
  28. struct ViewPort *vport;         /* pointer to window's ViewPort */
  29.  
  30. struct IntuiMessage *message;   /* pointer to window IDCMP messages */
  31.  
  32. struct VSprite *MyVSprite, *MyBob;
  33.  
  34. WORD MySpriteColors[] = {0x0000, 0x00f0, 0x0f00};
  35.  
  36. WORD MySpriteData[22] = {
  37.     0xfc00, 0x0000,
  38.     0x8200, 0x7c00,
  39.     0xfa00, 0x7c00,
  40.     0xf400, 0x7800,
  41.     0xfa00, 0x7c00,
  42.     0xfd00, 0x6e00,
  43.     0x6e80, 0x0700,
  44.     0x0740, 0x0380,
  45.     0x03a0, 0x01c0,
  46.     0x01c0, 0x0080,
  47.     0x0080, 0x0000,
  48. };
  49.  
  50. WORD MyBobData[44] = {
  51.     0xfff0, 0x0000,     /* plane 1 */
  52.     0xc00c, 0x0000,
  53.     0xffcc, 0x0000,
  54.     0xff30, 0x0000,
  55.     0xffcc, 0x0000,
  56.     0xfff3, 0x0000,
  57.     0x3cfc, 0xc000,
  58.     0x003f, 0x3000,
  59.     0x000f, 0xcc00,
  60.     0x0003, 0xf000,
  61.     0x0000, 0xc000,
  62.  
  63.     0x0000, 0x0000,     /* plane 2 */
  64.     0x3ff0, 0x0000,
  65.     0x3ff0, 0x0000,
  66.     0x3fc0, 0x0000,
  67.     0x3ff0, 0x0000,
  68.     0x3cfc, 0x0000,
  69.     0x003f, 0x0000,
  70.     0x000f, 0xc000,
  71.     0x0003, 0xf000,
  72.     0x0000, 0xc000,
  73.     0x0000, 0x0000
  74. };
  75.  
  76. struct NewWindow nw = {         /* titler-window definition */
  77.     0, 0,               /* LeftEdge, TopEdge */
  78.     WIDTH, HEIGHT,      /* Width, Heigth */
  79.     -1, -1,             /* DetailPen, BlockPen */
  80.     /* IDCMPFlags */
  81.     CLOSEWINDOW|NEWSIZE|MOUSEMOVE|WINDOWDRAG,
  82.     /* Flags */
  83.     ACTIVATE|REPORTMOUSE|SIZEBBOTTOM|WINDOWCLOSE|WINDOWDEPTH
  84.         |WINDOWDRAG|WINDOWSIZING,
  85.     NULL,               /* FirstGadget */
  86.     NULL,               /* CheckMark */
  87.     "VSprite Example",  /* Title */
  88.     NULL,               /* Screen */
  89.     NULL,               /* BitMap */
  90.     80, 25,             /* MinWidth, MinHeight */
  91.     640, 200,           /* MaxWidth, MaxHeight */
  92.     WBENCHSCREEN        /* Type */
  93. };
  94.  
  95.  
  96. /****************************************************************************
  97.  *                                M A I N                                   *
  98.  ****************************************************************************/
  99.  
  100. main()
  101. {       
  102.     BOOL MouseMoved;
  103.     UWORD i;                    /* general purpose index variable */
  104.     UWORD x, y;
  105.  
  106.     /* open libraries, bail out if there is a problem */
  107.     if((IntuitionBase = (struct IntuitionBase *)
  108.         OpenLibrary("intuition.library", 0)) == NULL)KillVS();
  109.     if((GfxBase = (struct GfxBase *)
  110.         OpenLibrary("graphics.library", 0)) == NULL)KillVS();
  111.  
  112.     /* open window, abort if unable */
  113.     if((window = OpenWindow(&nw)) == NULL)KillVS();
  114.     rport = window->RPort;
  115.     vport = ViewPortAddress(window);
  116.  
  117.     SetDrMd(rport, JAM1);
  118.  
  119.     MakeGelsInfo(rport, 0xfc);
  120.  
  121.     MyVSprite = MakeVSprite(160, 100, 11, 1, 2, MySpriteData, MySpriteColors);
  122.     AddVSprite(MyVSprite, rport);
  123.  
  124.     MyBob = MakeBob(160, 100, 11, 2, 2, MyBobData, DEPTH, 0x03, 0x00);
  125.     AddBob(MyBob->VSBob, rport);
  126.  
  127.     ON_SPRITE;
  128.     SortGList(rport);
  129.     DrawGList(rport, vport);
  130.     RethinkDisplay();
  131.  
  132.     FOREVER
  133.     {
  134.         Wait(1 << window->UserPort->mp_SigBit);
  135.         MouseMoved = FALSE;
  136.         while(message = GetMsg(window->UserPort))
  137.         {
  138.             switch(message->Class)
  139.             {
  140.                 case CLOSEWINDOW:
  141.                     ReplyMsg(message);
  142.                     KillVS();
  143.                     break;
  144.                 case MOUSEMOVE:
  145.                     MouseMoved = TRUE;
  146.                     x = message->MouseX;
  147.                     y = message->MouseY;
  148.                     ReplyMsg(message);
  149.                     break;
  150.                 default:
  151.                     ReplyMsg(message);
  152.             }
  153.         }
  154.  
  155.         if(MouseMoved = TRUE)
  156.         {
  157.             MyVSprite->X = x + 20;
  158.             MyVSprite->Y = y + 1;
  159.             if( (x < (window->Width - window->BorderRight - 16))
  160.                 && (x > window->BorderLeft) &&
  161.                 (y < (window->Height - window->BorderBottom - 16))
  162.                 && (y > window->BorderTop))
  163.             {
  164.                 MyBob->X = x;
  165.                 MyBob->Y = y + 10;
  166.             }
  167.             SortGList(rport);
  168.             Forbid();
  169.             DrawGList(rport, vport);
  170.             Permit();
  171.             RethinkDisplay();
  172.         }
  173.     } 
  174. }
  175.  
  176.  
  177. /* ======================================================================== */
  178. /* ==== KillVS: Kill/Exit VSprite Example ================================= */
  179. /* ==== free any allocated memory, close window if open, close any     ==== */
  180. /* ==== open libraries, and make sure WorkBench is open                ==== */
  181. /* ======================================================================== */
  182.  
  183. KillVS()
  184. {
  185.     DeleteVSprite(MyBob, DEPTH);
  186.     DeleteVSprite(MyVSprite, DEPTH);
  187.  
  188.     Forbid();
  189.     SortGList(rport);
  190.     DrawGList(rport, vport);
  191.     Permit();
  192.     RethinkDisplay();
  193.     DeleteGelsInfo(rport->GelsInfo);
  194.     
  195.     if(window != NULL)
  196.         CloseWindow(window);
  197.  
  198.     /* Close any open libraries */
  199.     if(GfxBase != NULL)
  200.         CloseLibrary(GfxBase);
  201.     if(IntuitionBase != NULL)
  202.         CloseLibrary(IntuitionBase);
  203.  
  204.     /* Open WorkBench, exit */
  205.     OpenWorkBench();
  206.     exit(0);
  207. }
  208.  
  209.  
  210. /* =========================== END OF FILE ================================ */
  211.  
  212.  
  213.